package br.com.vti.leilao.view.bean;

import java.util.List;

import br.com.vti.leilao.model.business.Business;
import br.com.vti.leilao.model.business.exception.ApplicationException;
import br.com.vti.leilao.model.entity.Ganhador;
import br.com.vti.leilao.model.entity.Leilao;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

@ManagedBean
@ViewScoped
public class GanhadorBean extends CommonBean<Ganhador, ApplicationException> {

    private static final long serialVersionUID = 7053723507220511445L;
    
    @ManagedProperty("#{ganhadorBusiness}")
    private Business<Ganhador, ApplicationException> business;

    /* (non-Javadoc)
     * @see br.com.vti.leilao.view.bean.Bean#getBusiness()
     */
    @Override
    public Business<Ganhador, ApplicationException> getBusiness() {
        return business;
    }

    /* (non-Javadoc)
     * @see br.com.vti.leilao.view.bean.Bean#setBusiness(br.gov.ce.saude.sesacore.business.Business)
     */
    @Override
    public void setBusiness(Business<Ganhador, ApplicationException> sesaBusiness) {
        this.business = sesaBusiness;
    }

    @Override
    public void limpar() {
        super.limpar();
        resetCadastro();
    }

    private void resetCadastro() {
    	try {
            List<Ganhador> list = getBusiness().getDao().listarPorExemplo(getEntidadePesquisa(), 100);
            setListaEntidade(list);
        } catch (Exception e) {
            getLogger().error(e);
        }
    }

    @Override
    public void resetCadastro(ActionEvent event) {
        super.resetCadastro(event);
        resetCadastro();
    }

}